package com.itheima.health.service.impl;

import com.itheima.health.dao.OrderSettingDao;
import com.itheima.health.pojo.OrderSetting;
import com.itheima.health.pojo.OrderSettingVO;
import com.itheima.health.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
public class OrderSettingServiceImpl implements OrderSettingService {
    @Resource
    private OrderSettingDao orderSettingDao;

    @Override
    public List<OrderSettingVO> getOrderSettingByMouth(LocalDate beginTime, LocalDate endTime) {
        List<OrderSetting> orderSetting = orderSettingDao.getOrderSettingByMouth(beginTime, endTime);
        List<OrderSettingVO> orderSettingVO = new ArrayList<>();
        for (OrderSetting setting : orderSetting) {
            OrderSettingVO o = new OrderSettingVO();
            o.setNumber(setting.getNumber());
            o.setReservations(setting.getReservations());
            o.setDate(Integer.parseInt(setting.getOrderDate().toString().substring(8, 10)));
            orderSettingVO.add(o);
        }
        return orderSettingVO;
    }

    @Override
    public void editNumberByDate(OrderSetting orderSetting) {
        if(orderSettingDao.selectByDate(orderSetting.getOrderDate())>0){
            orderSettingDao.editNumberByDate(orderSetting);
        }
        orderSettingDao.AddByDate(orderSetting);
    }
}
